﻿using System.Collections.Generic;
namespace NodeEditor
{
    public class RuntimeEdge
    {
        public string inputKey { get; private set; }
        public string ouputKey { get; private set; }
        public RuntimeNode input { get; private set; }
        public RuntimeNode ouput { get; private set; }
        
        RuntimeEdge(RuntimeNode input, RuntimeNode ouput)
        {
            this.input = input;
            this.ouput = ouput;
        }
        public void DisConnect()
        {
            input?.DisConnectPort(inputKey, this, PortDirection.Input);
            ouput?.DisConnectPort(ouputKey, this, PortDirection.Output);
        }

        public override string ToString()
        {
            return $"[{input}] connectTo [{ouput}]";
        }
        public static RuntimeEdge Connect(string inputKey,string ouputKey, RuntimeNode input, RuntimeNode output)
        {
            var edge = new RuntimeEdge(input, output);
            edge.inputKey = inputKey;
            edge.ouputKey = ouputKey;
            var inputPort = input.ConnectPort(inputKey, edge, NodeEditor.PortDirection.Input);
            var ouputPort = output.ConnectPort(ouputKey, edge, NodeEditor.PortDirection.Output);
            ouputPort.RuntimeValue = inputPort.RuntimeValue;
            return edge;
        }
    }

}